<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/content/variable.jsp" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
    <%@ include file="/content/head.jsp" %>
</head>
<body>
<div class="row">
    <div class="col-md-12">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">修改韩国视频内容</h3>
            </div>
            <form id="addInfo" class="form-horizontal" role="form">
                <div class="box-body">
                    <div class="form-group">
                        <label for="videoName" class="col-sm-2 control-label">视频名称：</label>
                        <div class="col-sm-8 ">
                            <input type="text" id="videoName" class="form-control" name="videoName"
                                 value="${obj.videoName}"  placeholder="视频名称">
                        </div>
                    </div>
                    <br>
                    <div class="form-group">
                        <label  class="col-sm-2 control-label">分类：</label>
                        <div class="col-sm-8 ">
                            <label>
                                <input type="radio"checked name="classification" value="1"
                                <c:if test="${obj.classification eq 1}">checked</c:if>
                                       class="flat-red">大片
                            </label>
                            <label>
                                <input type="radio"  name="classification" value="2"
                                       <c:if test="${obj.classification eq 2}">checked</c:if>
                                       class="flat-red">电影分类
                            </label>
                        </div>
                    </div>
                    <br>
                    <div class="form-group">
                        <label for="videoCoverFile" class="col-sm-2 control-label">视频封面：</label>
                        <div class="col-md-8">
                            <input type="file" class="file-loading" id="videoCoverFile" accept="image/*">
                            <input type="text"  class="form-control input-sm" id="videoCoverUrl"
                                   name="videoCover" value="${obj.videoCover}">
                        </div>
                        <div class="col-sm-2">
                            <span class="help-inline" style="color: #a94442"></span>
                        </div>
                    </div>
                    <br>
                    <div class="form-group">
                        <label for="videoHorizontalScreenImageFile" class="col-sm-2 control-label">横屏封面：</label>
                        <div class="col-md-8">
                            <input type="file" class="file-loading" id="videoHorizontalScreenImageFile" accept="image/*">
                            <input type="text" class="form-control input-sm" id="videoHorizontalScreenImage"
                                  value="${obj.videoHorizontalScreenImage}" name="videoHorizontalScreenImage">
                        </div>
                        <div class="col-sm-2">
                            <span class="help-inline" style="color: #a94442"></span>
                        </div>
                    </div>
                    <br>
                    <div class="form-group">
                        <label for="videoDesc" class="col-sm-2 control-label">视频简介：</label>
                        <div class="col-sm-8 ">
                            <input type="text" id="videoDesc" class="form-control" name="videoDesc"
                                 value="${obj.videoDesc}"  placeholder="视频简介">
                        </div>
                    </div>
                    <br>
                    <div class="form-group">
                        <label for="videoType" class="col-sm-2 control-label">视频类型：</label>
                        <div class="col-sm-8 ">
                            <input type="text" id="videoType" class="form-control" name="videoType"
                                 value="${obj.videoType}"  placeholder="视频类型">
                        </div>
                    </div>
                    <br>
                    <div class="form-group">
                        <label for="region" class="col-sm-2 control-label">地区：</label>
                        <div class="col-sm-8 ">
                            <input type="text" id="region" class="form-control" name="region"
                                 value="${obj.region}"  placeholder="地区">
                        </div>
                    </div>
                    <br>
                    <div class="form-group">
                        <label for="videoTime" class="col-sm-2 control-label">视频时长：</label>
                        <div class="col-sm-8 ">
                            <input type="text" id="videoTime" class="form-control" name="videoTime"
                                  value="${obj.videoTime}" placeholder="视频时长">
                        </div>
                    </div>
                    <br>
                    <div class="form-group">
                        <label for="videoScore" class="col-sm-2 control-label">视频评分：</label>
                        <div class="col-sm-8 ">
                            <input type="text" id="videoScore" class="form-control" name="videoScore"
                                 value="${obj.videoScore}"  placeholder="视频评分">
                        </div>
                    </div>
                    <br>
                    <div class="form-group">
                        <label for="tryToSeeUrlFile" class="col-sm-2 control-label">试看地址：</label>
                        <div class="col-md-8">
                            <input type="file" class="file-loading" id="tryToSeeUrlFile" accept="video/*">
                            <input type="text"  class="form-control input-sm" id="tryToSeeUrl"
                                   name="tryToSeeUrl" value="${obj.tryToSeeUrl}">
                        </div>
                        <div class="col-sm-2">
                            <span class="help-inline" style="color: #a94442"></span>
                        </div>
                    </div>
                    <br>

                    <div class="form-group">
                        <label for="seeUrlFile" class="col-sm-2 control-label">正片地址：</label>
                        <div class="col-md-8">
                            <input type="file" class="file-loading" id="seeUrlFile" accept="video/*">
                            <input type="text"  class="form-control input-sm" id="seeUrl"
                                   name="seeUrl" value="${obj.seeUrl}">
                        </div>
                        <div class="col-sm-2">
                            <span class="help-inline" style="color: #a94442"></span>
                        </div>
                    </div>
                    <br>

                    <div class="form-group">
                        <label  class="col-sm-2 control-label">视频分类：</label>
                        <div class="col-sm-8 ">
                            <label>
                                <input type="radio"checked name="videoClassification" value="1"
                                <c:if test="${obj.videoClassification eq 1}">checked</c:if>
                                       class="flat-red">热门
                            </label>
                            <label>
                                <input type="radio"  name="videoClassification" value="2"
                                       <c:if test="${obj.videoClassification eq 2}">checked</c:if>
                                       class="flat-red">最新
                            </label>
                        </div>
                    </div>
                    <br>

                    <div class="form-group">
                        <label for="videoWeight" class="col-sm-2 control-label">视频权重：</label>
                        <div class="col-sm-8 ">
                            <input type="text" id="videoWeight" class="form-control" name="videoWeight"
                                 value="${obj.videoWeight}"  placeholder="视频权重,值越大，排序越靠前">
                        </div>
                    </div>
                    <br>
                    <input type="hidden" name="id" value="${obj.id}">
                    <div class="col-md-offset-5 col-md-9">
                        <button type="submit" class="btn btn-success">确定</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- /.row -->
<%@ include file="/content/js.jsp" %>
<script type="text/javascript">
    $(function () {
        $('#addInfo').bootstrapValidator({
            message: '此值无效',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                videoName: {
                    message: '视频名称验证失败',
                    validators: {
                        notEmpty: {
                            message: '视频名称不能为空'
                        }
                    }
                },
                // videoCover: {
                //     message: '视频封面验证失败',
                //     validators: {
                //         notEmpty: {
                //             message: '视频封面不能为空'
                //         }
                //     }
                // },
                videoDesc: {
                    message: '视频简介验证失败',
                    validators: {
                        notEmpty: {
                            message: '视频简介不能为空'
                        }
                    }
                },
                videoType: {
                    message: '视频类型验证失败',
                    validators: {
                        notEmpty: {
                            message: '视频类型不能为空'
                        }
                    }
                },
                region: {
                    message: '地区验证失败',
                    validators: {
                        notEmpty: {
                            message: '视地区不能为空'
                        }
                    }
                },
                videoTime: {
                    message: '视频时长验证失败',
                    validators: {
                        notEmpty: {
                            message: '视频时长不能为空'
                        }
                    }
                },
                videoScore: {
                    message: '视频评分验证失败',
                    validators: {
                        notEmpty: {
                            message: '视频评分不能为空'
                        }
                    }
                },
                // tryToSeeUrl: {
                //     message: '试看地址验证失败',
                //     validators: {
                //         notEmpty: {
                //             message: '试看地址不能为空'
                //         }
                //     }
                // },
                // seeUrl: {
                //     message: '正片地址验证失败',
                //     validators: {
                //         notEmpty: {
                //             message: '正片地址不能为空'
                //         }
                //     }
                // },

            }
        }).on('success.form.bv', function (e) {//点击提交之后
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            saveInfo();
        });
//封面上传
        $("#videoCoverFile").fileinput({
            uploadUrl: "<%=path%>/korean/video/uploadClassifyImg",
            browseClass: "btn btn-primary",
            enctype: 'multipart/form-data',
            autoReplace: true,
            dropZoneEnabled: false,
            browseLabel: "上传",
            showCaption: false,
            showRemove: false,
            showUpload: true,
            showZoom: false,
            maxFileCount: 1, ////表示允许同时上传的最大文件个数
            allowedFileTypes: ["image"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
            previewSettings: {
                image: {width: "auto", height: "100px"},
            },
        });
        $('#videoCoverFile').on('fileuploaded', function (event, data, previewId, index) {
            var path = data.response.initialPreviewConfig[0].extra.path;
            $("#videoCoverUrl").val(path);
        });
        $('#videoCoverFile').on('filedeleted', function (event, key, jqXHR, data) {
            if ($("#videoCoverUrl").val() == data.path)
                $("#videoCoverUrl").val('');
        });

        $("#videoHorizontalScreenImageFile").fileinput({
            uploadUrl: "<%=path%>/korean/video/uploadClassifyImg",
            browseClass: "btn btn-primary",
            enctype: 'multipart/form-data',
            autoReplace: true,
            dropZoneEnabled: false,
            browseLabel: "上传",
            showCaption: false,
            showRemove: false,
            showUpload: true,
            showZoom: false,
            maxFileCount: 1, ////表示允许同时上传的最大文件个数
            allowedFileTypes: ["image"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
            previewSettings: {
                image: {width: "auto", height: "100px"},
            },
        });
        $('#videoHorizontalScreenImageFile').on('fileuploaded', function (event, data, previewId, index) {
            var path = data.response.initialPreviewConfig[0].extra.path;
            $("#videoHorizontalScreenImage").val(path);
        });
        $('#videoHorizontalScreenImageFile').on('filedeleted', function (event, key, jqXHR, data) {
            if ($("#videoHorizontalScreenImage").val() == data.path)
                $("#videoHorizontalScreenImage").val('');
        });

        //视频上传
        //这里发现fileinput有用一个bug
        //当要上传文件大于50MB左右的时候,如果开启了文件预览则点击上传按钮并不会触发上传事件
        //解决方法：showPreview:false 关闭预览即可上传大于50MB的文件
        //另：根据实际使用，本地测试阿里OSS一般每上传10MB需要约1分钟
        $("#tryToSeeUrlFile").fileinput({
            uploadUrl: "<%=path%>/korean/video/uploadClassifyVideo",
            browseClass: "btn btn-primary",
            autoReplace: true,
            dropZoneEnabled: false,
            browseLabel: "上传",
            showCaption: false,
            showRemove: false,
            showPreview: false,
            showUpload: true,
            showZoom: false,
            maxFileCount: 1, ////表示允许同时上传的最大文件个数
//        allowedFileTypes:["video"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
            maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
            previewSettings: {
                type: "video",
                video: {width: "auto", height: "100px"},
            },
        });
        $('#tryToSeeUrlFile').on('fileuploaded', function (event, data, previewId, index) {
            var path = data.response.initialPreviewConfig[0].extra.path;
            $("#tryToSeeUrl").val(path);
            $("#tryToSeeUrl").triggerHandler("blur");
        });
        $('#tryToSeeUrlFile').on('filedeleted', function (event, key, jqXHR, data) {
            if ($("#tryToSeeUrl").val() == data.path)
                $("#tryToSeeUrl").val('');
            $("#tryToSeeUrl").triggerHandler("blur");
        });

        $("#seeUrlFile").fileinput({
            uploadUrl: "<%=path%>/korean/video/uploadClassifyVideo",
            browseClass: "btn btn-primary",
            autoReplace: true,
            dropZoneEnabled: false,
            browseLabel: "上传",
            showCaption: false,
            showRemove: false,
            showPreview: false,
            showUpload: true,
            showZoom: false,
            maxFileCount: 1, ////表示允许同时上传的最大文件个数
//        allowedFileTypes:["video"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
            maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
            previewSettings: {
                type: "video",
                video: {width: "auto", height: "100px"},
            },
        });
        $('#seeUrlFile').on('fileuploaded', function (event, data, previewId, index) {
            var path = data.response.initialPreviewConfig[0].extra.path;
            $("#seeUrl").val(path);
            $("#seeUrl").triggerHandler("blur");
        });
        $('#seeUrlFile').on('filedeleted', function (event, key, jqXHR, data) {
            if ($("#seeUrl").val() == data.path)
                $("#seeUrl").val('');
            $("#seeUrl").triggerHandler("blur");
        });
    });

    function saveInfo() {
        $.post("<%=path%>/korean/video/edit",
            $("#addInfo").serialize()
            , function (data) {
                if (data.missage == "success") {
                    modalMsg("新增成功", "success");
                    window.parent.location.reload();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }else if(data.missage == "error"){
                    modalMsg("新增失败", "error");
                }else{
                    modalMsg("更新失败", "error");
                }
            }
        );
    }
</script>
</body>
</html>